/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import vo.VOUser;

/**
 *
 * @author sbaldrich
 */
@Entity
@Table(name = "user")
@NamedQueries(
{
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findByIdUser", query = "SELECT u FROM User u WHERE u.idUser = :idUser"),
    @NamedQuery(name = "User.findByHandle", query = "SELECT u FROM User u WHERE u.handle = :handle"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
    @NamedQuery(name = "User.findByFirstName", query = "SELECT u FROM User u WHERE u.firstName = :firstName"),
    @NamedQuery(name = "User.findByLastName", query = "SELECT u FROM User u WHERE u.lastName = :lastName"),
    @NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email"),
    @NamedQuery(name = "User.findByInstitution", query = "SELECT u FROM User u WHERE u.institution = :institution"),
    @NamedQuery(name = "User.findByCountry", query = "SELECT u FROM User u WHERE u.country = :country"),
    @NamedQuery(name = "User.findByIsAdmin", query = "SELECT u FROM User u WHERE u.isAdmin = :isAdmin"),
    @NamedQuery(name = "User.findByTeam", query = "SELECT u FROM User u WHERE u.team = :team"),
    @NamedQuery(name = "User.findByRating", query = "SELECT u FROM User u WHERE u.rating = :rating"),
    @NamedQuery(name = "User.findBySubmissions", query = "SELECT u FROM User u WHERE u.submissions = :submissions"),
    @NamedQuery(name = "User.findByAccepted", query = "SELECT u FROM User u WHERE u.accepted = :accepted")
})
public class User implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idUser")
    private Integer idUser;
    @Basic(optional = false)
    @Column(name = "handle")
    private String handle;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @Column(name = "firstName")
    private String firstName;
    @Basic(optional = false)
    @Column(name = "lastName")
    private String lastName;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;
    @Basic(optional = false)
    @Column(name = "institution")
    private String institution;
    @Basic(optional = false)
    @Column(name = "country")
    private String country;
    @Basic(optional = false)
    @Column(name = "isAdmin")
    private boolean isAdmin;
    @Column(name = "team")
    private String team;
    @Column(name = "rating")
    private Integer rating;
    @Column(name = "submissions")
    private Integer submissions;
    @Column(name = "accepted")
    private Integer accepted;
    @ManyToMany(mappedBy = "userList")
    private List<Contest> contestList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private List<Submission> submissionList;

    public User()
    {
    }

    public User(Integer idUser)
    {
        this.idUser = idUser;
    }

    public User(Integer idUser, String handle, String password, String firstName, String lastName, String email, String institution, String country, boolean isAdmin)
    {
        this.idUser = idUser;
        this.handle = handle;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.institution = institution;
        this.country = country;
        this.isAdmin = isAdmin;
    }

    public User(VOUser vo)
    {
        this(vo.getIdUser(), vo.getHandle(), vo.getPassword(), vo.getFirstName(),
                vo.getLastName(), vo.getEmail(), vo.getInstitution(), vo.getCountry(), false);
    }

    public Integer getIdUser()
    {
        return idUser;
    }

    public void setIdUser(Integer idUser)
    {
        this.idUser = idUser;
    }

    public String getHandle()
    {
        return handle;
    }

    public void setHandle(String handle)
    {
        this.handle = handle;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getInstitution()
    {
        return institution;
    }

    public void setInstitution(String institution)
    {
        this.institution = institution;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public boolean getIsAdmin()
    {
        return isAdmin;
    }

    public void setIsAdmin(boolean isAdmin)
    {
        this.isAdmin = isAdmin;
    }

    public String getTeam()
    {
        return team;
    }

    public void setTeam(String team)
    {
        this.team = team;
    }

    public Integer getRating()
    {
        return rating;
    }

    public void setRating(Integer rating)
    {
        this.rating = rating;
    }

    public Integer getSubmissions()
    {
        return submissions;
    }

    public void setSubmissions(Integer submissions)
    {
        this.submissions = submissions;
    }

    public Integer getAccepted()
    {
        return accepted;
    }

    public void setAccepted(Integer accepted)
    {
        this.accepted = accepted;
    }

    public List<Contest> getContestList()
    {
        return contestList;
    }

    public void setContestList(List<Contest> contestList)
    {
        this.contestList = contestList;
    }

    public List<Submission> getSubmissionList()
    {
        return submissionList;
    }

    public void setSubmissionList(List<Submission> submissionList)
    {
        this.submissionList = submissionList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idUser != null ? idUser.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User))
        {
            return false;
        }
        User other = (User) object;
        if ((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.User[idUser=" + idUser + "]";
    }

    public VOUser getVO()
    {
        return new VOUser(this);
    }
}
